<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class GroupJoin extends FormRequest
{
    private $userId = null;
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        $this->userId = auth('api')->user()->id;
        return $this->userId;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $rule = [
            'group_id'=>'bail|required|unique:group_joins,group_id,'.$this->userId.'user_id',
        ];
        return $rule;
    }

    /**
     * 获取已定义的验证规则的错误消息。
     *
     * @return array
     */
    public function messages()
    {
        return [
            'group_id.required' => '圈子id不能为空',
            'group_id.unique' => '不需要重新加入圈子',
        ];
    }
}
